package com.heima.big_event03.controller;

import com.heima.big_event03.entity.Article;
import com.heima.big_event03.entity.PageBean;
import com.heima.big_event03.service.ArticleService;
//import org.springframework.data.domain.Page;
//import org.springframework.data.domain.PageRequest;
import com.heima.big_event03.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Article)表控制层
 *
 * @author makejava
 * @since 2025-03-04 20:44:00
 */
@RestController
@RequestMapping("article")
@Api("文章信息")
public class ArticleController {
    /**
     * 服务对象
     */
    @Resource
    private ArticleService articleService;

    /**
     * 新增文章
     * @return
     */
    @PostMapping
    @ApiOperation("新增文章")
    public Result addActicle(@RequestBody Article a){
        this.articleService.insert(a);
        return Result.success();
    }

    /**
     * 文章列表
     * @return
     */
    @GetMapping
    @ApiOperation("文章列表")
    public Result<PageBean<Article>> list(Integer pageNum,
                                      Integer pageSize,
                                      @RequestParam(required = false) Integer categoryId,
                                      @RequestParam(required = false) String state){
        PageBean<Article> pb = articleService.list(pageNum,pageSize,categoryId,state);
        return Result.success(pb);
    }

    /**
     *获取文章详情
     * @return
     */
    @GetMapping("/detail")
    @ApiOperation("获取文章详情")
    public Result<Article> getDetail(String id){
        Article a = this.articleService.queryById(id);
        return Result.success(a);
    }

    /**
     *更新文章
     * @return
     */
    @PutMapping
    @ApiOperation("更新文章")
    public Result updateArticle(@RequestBody Article a){
        this.articleService.update(a);
        return Result.success();
    }

    /**
     *删除文章
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除文章")
    public Result deteleArticle(String id){
        this.articleService.deleteById(id);
        return Result.success();
    }

}

